package etf.tests;


import etf.db40.SimpleDb4o;
import etf.hibernate.SimpleHibernate;
import etf.jdbc.SimpleJDBC;
import etf.library.Address;
import etf.library.IndexedAddress;

/*
 * klasa kroz koju pokrecemo sve jednostavne testove
 * za Db4o, Hibernate/MySQL i JDBC/MySQL
 */
public class SimpleTest extends Test{
	private SimpleDb4o 			db4o;
	private SimpleHibernate 	hibernate;
	private SimpleJDBC 			jdbc;
	private int inserts[] ={50000};

	public SimpleTest() {
		db4o 		= new SimpleDb4o("simpleTest");
		hibernate 	= new SimpleHibernate();
		jdbc 		= new SimpleJDBC();
	}
	
	public void testAll(){
		printSeparator(0);
		System.out.println("    TESTIRANJE INSERTA, QUERY-A, UPDATE-A I DELETE-A JEDNOSTAVNOG OBJEKTA");
//		clearAddress();
//		clearIndexedAddress();
		for (int i = 0; i < inserts.length; i++){
//			printSeparator(50);
//			System.out.println("                INSERT");
//			printSeparator(50);
//			System.out.println("------------Bez indeksa-------------------------");
//			System.out.println("Insert " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.insert(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.insert(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.insert(inserts[i]) + " ms");
			
//			System.out.println("------------Sa indeksom-------------------------");
//			System.out.println("Insert " + inserts[i] + " slogova sa 2 indeksirana polja");
//			System.out.println("Db40           : " + db4o.indexedInsert(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.indexedInsert(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.indexedInsert(inserts[i]) + " ms");
			
//			printSeparator(50);
//			System.out.println("                QUERY");
//			printSeparator(50);
//			System.out.println("------------Bez indeksa-------------------------");
//			System.out.println("Pretrazivanje sloga nad " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.query(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.query(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.query(inserts[i]) + " ms");
			
//			System.out.println("------------Sa indeksom na int polju ------------");
//			System.out.println("Pretrazivanje sloga nad " + inserts[i] + " slogova nad indeksiranim poljem");
//			System.out.println("Db40           : " + db4o.indexedQueryInt(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.indexedQueryInt(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.indexedQueryInt(inserts[i]) + " ms");
//			
//			System.out.println("------------Sa indeksom na string polju ---------");
//			System.out.println("Pretrazivanje sloga nad " + inserts[i] + " slogova nad indeksiranim poljem");
//			System.out.println("Db40           : " + db4o.indexedQueryString(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.indexedQueryString(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.indexedQueryString(inserts[i]) + " ms");
			
//			printSeparator(50);
//			System.out.println("                UPDATE");
//			printSeparator(50);			
//			System.out.println("Pretrazivanje sloga nad " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.update(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.update(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.update(inserts[i]) + " ms");
			
			printSeparator(50);
			System.out.println("                DELETE RANDOM");
			printSeparator(50);
			System.out.println("------------Bez indeksa-------------------------");
			System.out.println("Brisanje sloga od " + inserts[i] + " slogova");
			System.out.println("Db40           : " + db4o.delete(inserts[i]) + " ms");
			System.out.println("Hibernate/MySQL: " + hibernate.delete(inserts[i]) + " ms");
			System.out.println("JDBC/MySQL     : " + jdbc.delete(inserts[i]) + " ms");
			
//			System.out.println("------------Sa indeksom-------------------------");
//			System.out.println("Brisanje sloga od " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.indexedDelete(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.indexedDelete(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.indexedDelete(inserts[i]) + " ms");
			
//			printSeparator(50);
//			System.out.println("                DELETE ALL");
//			printSeparator(50);
//			System.out.println("Delete " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.deleteAll(Address.class) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.deleteAll("Address") + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.deleteAll("address") + " ms");
			
			printSeparator(50);
//			clearAddress();
//			clearIndexedAddress();
		}

	}

	@SuppressWarnings("unused")
	private void clearIndexedAddress(){
		db4o.deleteAll(IndexedAddress.class);
		hibernate.deleteAll("IndexedAddress");
		jdbc.deleteAll("indexed_address");
	}
	
	private void clearAddress(){
		db4o.deleteAll(Address.class);
		hibernate.deleteAll("Address");
		jdbc.deleteAll("address");
	}
	
	public void closeSesions() {
		db4o.closeDatabase();
		hibernate.closeSession();
		
	}


}
